#ifndef UI_MANAGER_H
#define UI_MANAGER_H

#include <gtk/gtk.h>
#include <string>

// 前向声明
class CabrilloConfigDialog;
class FunctionButtonManager;

// 回调函数声明
extern "C" void on_cw_cabrillo_button_clicked(GtkWidget* widget, gpointer data);
extern "C" void on_export_cabrillo_button_clicked(GtkWidget* widget, gpointer data);
extern "C" void on_export_ADI_button_clicked(GtkWidget* widget, gpointer data);

class UIManager {
public:
    static GtkBuilder* create_builder();
    static GtkWidget* get_main_window(GtkBuilder *builder);
    static void apply_css_styles(GtkBuilder *builder, GtkWidget *window);
    static void connect_signals(GtkBuilder *builder);
    static std::string get_ui_path();
    
    // 新增：保存builder对象的静态成员函数
    static void set_builder(GtkBuilder* builder);
    static GtkBuilder* get_builder();
    
    // Cabrillo日志导出函数
    static bool export_cabrillo_log(const std::string& filename);
    
    // ADI日志导出函数
    static bool export_adi_log(const std::string& filename);

private:
    static GtkBuilder* current_builder;  // 保存当前的builder对象
    
    // Cabrillo导出辅助函数
    static std::string bandToFrequency(const std::string& band);
    static std::string formatDateForCabrillo(const std::string& date);
    static std::string formatTimeForCabrillo(const std::string& time);
};

// 新增回调函数声明
extern "C" {
    G_MODULE_EXPORT void on_frequency_changed(GtkWidget *entry, gpointer data);
    G_MODULE_EXPORT void on_wpm_changed(GtkWidget *combo, gpointer data);
    G_MODULE_EXPORT gboolean on_frequency_focus_out(GtkWidget *entry, GdkEvent *event, gpointer data);
    G_MODULE_EXPORT gboolean on_frequency_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    
    // 新增输入框相关回调函数
    G_MODULE_EXPORT gboolean on_callsign_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    G_MODULE_EXPORT void on_callsign_changed(GtkWidget *entry, gpointer data);
    G_MODULE_EXPORT gboolean on_callsign_focus_out(GtkWidget *entry, GdkEvent *event, gpointer data);
    G_MODULE_EXPORT gboolean on_snt_focus_in(GtkWidget *entry, GdkEvent *event, gpointer data);
    G_MODULE_EXPORT gboolean on_snt_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    G_MODULE_EXPORT gboolean on_rcv_focus_in(GtkWidget *entry, GdkEvent *event, gpointer data);
    G_MODULE_EXPORT gboolean on_rcv_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    G_MODULE_EXPORT gboolean on_name_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    G_MODULE_EXPORT gboolean on_memo_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
    G_MODULE_EXPORT gboolean on_sendjust_key_press(GtkWidget *entry, GdkEventKey *event, gpointer data);
}

#endif // UI_MANAGER_H